﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ClassLibrary.DAO;

namespace mprsc
{
    public partial class JobListWarranty : Form
    {
        TblJobsDAO jobDAO = new TblJobsDAO(Global.CONNECTION_STRING);
        int demjobwarranty;
        int dempickup;

        public JobListWarranty()
        {
            InitializeComponent();
        }

        private void JobListWarranty_Load(object sender, EventArgs e)
        {
            this.CenterToScreen();
            loadjobWarranty();
            loadcustomerpickup();
            txtDem.Text = Convert.ToString(demjobwarranty);
            txtDemPickUp.Text = Convert.ToString(dempickup);
        }

        private void loadjobWarranty()
        {
            try
            {
                grdJobList.DataSource = jobDAO.GetJobNonWarranty(1, 2);
                demjobwarranty = Convert.ToInt32(grdJobList.Rows.Count);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        private void loadcustomerpickup()
        {
            grdpickup.DataSource = jobDAO.GetJobNonWarranty(3, 2);
            dempickup = Convert.ToInt32(grdpickup.Rows.Count);
        }

        private void btnDetailJobActive_Click(object sender, EventArgs e)
        {
            string id = grdJobList.CurrentRow.Cells["JobID"].Value.ToString();
            this.Hide();
            NewBooking newBook = new NewBooking();
            newBook.Sender1(id);
            newBook.Show();
        }

        private void btnUpdateStatus_Click(object sender, EventArgs e)
        {
            bool flag = false;
            try
            {
                string id = grdpickup.CurrentRow.Cells["IDJob"].Value.ToString();
                if (grdpickup.CurrentRow.Cells["Status"].Value.ToString() == "Waiting...")
                {
                    jobDAO.Update(2, Global.ConvertToInt(id));
                }
                else
                {
                    jobDAO.Update(0, Global.ConvertToInt(id));
                }
                flag = true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            if (flag)
            {
                loadcustomerpickup();
            }
        }
    }
}
